Martin Buck adds support for packet IDs and sizes > 255.
authorrobertl <robertl>
Tue, 16 Feb 2010 00:28:35 +0000 (00:28 +0000)
committerrobertl <robertl>
Tue, 16 Feb 2010 00:28:35 +0000 (00:28 +0000)
16 files changed:
jeeps/gps.h
jeeps/gpsapp.c
jeeps/gpsapp.h
jeeps/gpscom.c
jeeps/gpsdevice.c
jeeps/gpsdevice.h
jeeps/gpsdevice_ser.c
jeeps/gpsdevice_usb.c
jeeps/gpsmem.c
jeeps/gpsprot.h
jeeps/gpsread.c
jeeps/gpssend.c
jeeps/gpssend.h
jeeps/gpsusbcommon.c
jeeps/gpsusbread.c
jeeps/gpsusbsend.c

index 42018a6a27cb63878f98f553ca6f6a73aecfb344..54c492f965846b2fe28d4d8b9ef235a8e3d20087 100644 (file)
@@ -37,6 +37,13 @@ extern char gps_categories[16][17];
 
 
 typedef struct GPS_SPacket
+{
+    US type;
+    uint32 n;
+    UC *data;
+} GPS_OPacket, *GPS_PPacket;
+
+typedef struct GPS_Serial_SPacket
 {
     UC dle;
     UC type;
@@ -45,10 +52,7 @@ typedef struct GPS_SPacket
     UC chk;
     UC edle;
     UC etx;
-    UC bytes;          /* Actual number of bytes (for sending) */    
-} GPS_OPacket, *GPS_PPacket;
-
-
+} GPS_Serial_OPacket, *GPS_Serial_PPacket;
 
 typedef struct GPS_SProduct_Data_Type
 {
index 81ef74c908c9fcbf4b3efaded404c3e55a078025..9bcb95a6ef5d96a5b3f309a98d2df433f794ea4d 100644 (file)
@@ -985,7 +985,7 @@ int32 GPS_A100_Send(const char *port, GPS_PWay *way, int32 n, int (*cb)(GPS_PWay
        }
 
        GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Wpt_Data,
-                  data, (US) len);
+                  data, len);
 
        if(!GPS_Write_Packet(fd,tra))
            return gps_errno;
@@ -2922,7 +2922,7 @@ int32 GPS_A200_Send(const char *port, GPS_PWay *way, int32 n)
     GPS_PPacket rec;
     int32 i;
     int32 len;
-    UC  method;
+    US  method;
 
     if(!GPS_Device_On(port,&fd))
        return gps_errno;
@@ -3019,7 +3019,7 @@ int32 GPS_A200_Send(const char *port, GPS_PWay *way, int32 n)
        }
        
 
-       GPS_Make_Packet(&tra, method, data,(US) len);
+       GPS_Make_Packet(&tra, method, data, len);
 
        if(!GPS_Write_Packet(fd,tra))
            return gps_errno;
@@ -3071,7 +3071,7 @@ int32 GPS_A201_Send(const char *port, GPS_PWay *way, int32 n)
     GPS_PPacket rec;
     int32 i;
     int32 len;
-    UC  method;
+    US  method;
 
     if(!GPS_Device_On(port,&fd))
        return gps_errno;
@@ -3188,7 +3188,7 @@ int32 GPS_A201_Send(const char *port, GPS_PWay *way, int32 n)
        }
        
 
-       GPS_Make_Packet(&tra, method, data,(US) len);
+       GPS_Make_Packet(&tra, method, data, len);
 
        if(!GPS_Write_Packet(fd,tra))
            return gps_errno;
@@ -3776,7 +3776,7 @@ int32 GPS_A300_Send(const char *port, GPS_PTrack *trk, int32 n)
        }
 
        GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Trk_Data,
-                       data,(US) len);
+                       data, len);
 
        if(!GPS_Write_Packet(fd,tra))
            return gps_errno;
@@ -3828,7 +3828,7 @@ int32 GPS_A301_Send(const char *port, GPS_PTrack *trk, int32 n)
     GPS_PPacket rec;
     int32 i;
     int32 len;
-    UC  method;
+    US  method;
 
     if(gps_trk_transfer == -1)
        return GPS_UNSUPPORTED;
@@ -3912,14 +3912,14 @@ int32 GPS_A301_Send(const char *port, GPS_PTrack *trk, int32 n)
        }
        
 
-       GPS_Make_Packet(&tra, method, data,(US) len);
+       GPS_Make_Packet(&tra, method, data, len);
 
        if(!GPS_Write_Packet(fd,tra))
            return gps_errno;
 
        if(!GPS_Get_Ack(fd, &tra, &rec))
        {
-           GPS_Error("A301_Send: Track packet not acknowledgedn");
+           GPS_Error("A301_Send: Track packet not acknowledged");
            return FRAMING_ERROR;
        }
     }
@@ -4714,7 +4714,7 @@ int32 GPS_A400_Send(const char *port, GPS_PWay *way, int32 n)
        }
 
        GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Prx_Wpt_Data,
-                       data,(US) len);
+                       data, len);
 
        if(!GPS_Write_Packet(fd,tra))
            return gps_errno;
@@ -5174,7 +5174,7 @@ int32 GPS_A500_Send(const char *port, GPS_PAlmanac *alm, int32 n)
        }
 
        GPS_Make_Packet(&tra, LINK_ID[gps_link_type].Pid_Almanac_Data,
-                       data,(US) len);
+                       data, len);
 
        if(!GPS_Write_Packet(fd,tra))
            return gps_errno;
@@ -6070,7 +6070,7 @@ int32 GPS_A906_Get(const char *port, GPS_PLap **lap, pcb_fn cb)
        return MEMORY_ERROR;
 
     GPS_Util_Put_Short(data,
-                       COMMAND_ID[gps_device_command].Cmnd_Transfer_Lap);
+                       COMMAND_ID[gps_device_command].Cmnd_Transfer_Laps);
     GPS_Make_Packet(&trapkt, LINK_ID[gps_link_type].Pid_Command_Data,
                     data,2);
     if(!GPS_Write_Packet(fd,trapkt))
@@ -6246,7 +6246,7 @@ void GPS_D1011b_Get(GPS_PLap *Lap, UC *p)
  *  but they really are runtime variable.  Sigh.
  */
 const char *
-Get_Pkt_Type(unsigned char p, unsigned short d0, const char **xinfo)
+Get_Pkt_Type(US p, US d0, const char **xinfo)
 {
        *xinfo = NULL;
 #define LT LINK_ID[gps_link_type]
@@ -6325,7 +6325,7 @@ Get_Pkt_Type(unsigned char p, unsigned short d0, const char **xinfo)
                return "FLIBOO";
        if (p == LT.Pid_Lap)
                return "LAPDAT";
-       if (p == LT.Pid_Wpt_Cat_Data)
+       if (p == LT.Pid_Wpt_Cat)
                return "WPTCAT";
        if (p == LT.Pid_Run)
                return "RUNDAT";
index b303322d9a06085cb21e8972aead826fe01a15d4..04ed235287d24c20ea509aa0653895080656267a 100644 (file)
@@ -96,7 +96,7 @@ Capability A918: D918
 Capability A1013: D1014
 */
 
-const char * Get_Pkt_Type(unsigned char p, unsigned short d0, const char **xinfo);
+const char * Get_Pkt_Type(US p, US d0, const char **xinfo);
 
 
 #endif
index 3c5276ec2b3225d469a55680d4752d040092bcad..883593ff3039eb7342f08e7653fc16bb7fee3d90 100644 (file)
@@ -648,7 +648,7 @@ int32 GPS_Command_Pvt_Get(gpsdevh **fd, GPS_PPvt_Data *pvt)
 ** Get lap from GPS
 **
 ** @param [r] port [const char *] serial port
-** @param [w] way [GPS_PLap **] pointer to lap array
+** @param [w] lap [GPS_PLap **] pointer to lap array
 **
 ** @return [int32] number of lap entries
 ************************************************************************/
index 90c841f1b6ffaa7c4e560317901fea0651100dee..8c68bd6a0ba53585b4053247bb82552814c5f5e2 100644 (file)
@@ -80,7 +80,9 @@ int32 GPS_Get_Ack(gpsdevh * fd, GPS_PPacket *tra, GPS_PPacket *rec)
        return (ops->Get_Ack)(fd, tra, rec);
 }
 
-void GPS_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n)
+void GPS_Make_Packet(GPS_PPacket *packet, US type, UC *data, uint32 n)
 {
-       (ops->Make_Packet)(packet, type, data, n);
+       (*packet)->type = type;
+       memcpy((*packet)->data, data, n);
+       (*packet)->n = n;
 }
index eb5d53d96e9cd4255d733a8ca365f186321b60a9..c428ea1581b501ec2088847f532ebd2fc7663f99 100644 (file)
@@ -52,7 +52,6 @@ typedef int32 (*gps_device_op5)(const char *, gpsdevh **fd);
 typedef int32 (*gps_device_op10)(gpsdevh * fd,  GPS_PPacket *tra, GPS_PPacket *rec);
 typedef int32 (*gps_device_op12)(gpsdevh * fd, GPS_PPacket packet);
 typedef int32 (*gps_device_op13)(gpsdevh * fd, GPS_PPacket *packet);
-typedef void (*gps_device_op14)(GPS_PPacket *packet, UC type, UC *data, int16 n);
 typedef struct {
        gps_device_op5 Device_On;
        gps_device_op Device_Off;
@@ -62,7 +61,6 @@ typedef struct {
        gps_device_op10 Send_Ack;
        gps_device_op10 Get_Ack;
        gps_device_op13 Read_Packet;
-       gps_device_op14 Make_Packet;
        gps_device_op12 Write_Packet;
 } gps_device_ops;
 
index 29ff476e628fc1a50d40db75b0da64d52e316aef..ae6c3cd17f234e934606f33a79f717a0ccd81b15 100644 (file)
@@ -32,6 +32,5 @@ gps_device_ops  gps_serial_ops = {
        GPS_Serial_Send_Ack,
        GPS_Serial_Get_Ack,
        GPS_Serial_Packet_Read,
-       GPS_Serial_Make_Packet,
        GPS_Serial_Write_Packet,
 };
index dd578c8297c0f85914c42d16430f01c4f6781f8d..32cb0ef7335d6844e90092cb2366cb68ab9c2285 100644 (file)
@@ -54,6 +54,5 @@ gps_device_ops gps_usb_ops = {
        (gps_device_op10) success_stub,
        (gps_device_op10) success_stub,
        gdu_read,
-       GPS_Make_Packet_usb,
        GPS_Write_Packet_usb
 };
index e9ae4a3ecb7fe8ac995abfd8a53e3fd16af0b2dd..bfc92bcb79789d0fbac3da8a037cad2ba2ec1a67 100644 (file)
@@ -56,9 +56,6 @@ GPS_PPacket GPS_Packet_New(void)
        return NULL;
     }
 
-    ret->dle = ret->edle = DLE;
-    ret->etx = ETX;
-
     return ret;
 }
 
@@ -301,7 +298,7 @@ void GPS_Way_Del(GPS_PWay *thys)
 **
 ** Lap constructor
 **
-** @return [GPS_PLap] virgin track
+** @return [GPS_PLap] virgin lap
 **********************************************************************/
 
 GPS_PLap GPS_Lap_New(void)
@@ -325,7 +322,7 @@ GPS_PLap GPS_Lap_New(void)
 **
 ** Lap destructor
 **
-** @param [w] thys [GPS_PLap *] track to delete
+** @param [w] thys [GPS_PLap *] lap to delete
 **
 ** @return [void]
 **********************************************************************/
index 2e30d20c9613ddff7957949296199e4412982c13..09df347ebb1524725113c6a423c5451d7e321a0c 100644 (file)
@@ -38,7 +38,7 @@ struct LINKDATA
        
     US Pid_FlightBook_Record;
     US Pid_Lap;
-    US Pid_Wpt_Cat_Data;
+    US Pid_Wpt_Cat;
     US Pid_Run;
     US Pid_Workout;
     US Pid_Workout_Occurrence;
@@ -81,7 +81,7 @@ struct COMMANDDATA
     US Cmnd_Start_Pvt_Data;
     US Cmnd_Stop_Pvt_Data;
     US Cmnd_FlightBook_Transfer;
-    US Cmnd_Transfer_Lap;
+    US Cmnd_Transfer_Laps;
     US Cmnd_Transfer_Wpt_Cats;
     US Cmnd_Transfer_Runs;
     US Cmnd_Transfer_Workouts;
index 587f15c6fa4a05c02510cd64c58f797336cf0f72..2bf926b1dad8eebe112e08b1b59d48675b4c3985 100644 (file)
@@ -77,7 +77,7 @@ int32 GPS_Serial_Packet_Read(gpsdevh *fd, GPS_PPacket *packet)
     int32  isDLE;
     UC     *p;
     int32  i;
-    UC     chk=0;
+    UC     chk=0, chk_read;
     const char *m1;
     const char *m2;
     
@@ -103,7 +103,6 @@ int32 GPS_Serial_Packet_Read(gpsdevh *fd, GPS_PPacket *packet)
 
            if(!len)
            {
-               (*packet)->dle = u;
                if(u != DLE)
                {
                    (void) fprintf(stderr,"GPS_Packet_Read: No DLE.  Data received, but probably not a garmin packet.\n");
@@ -141,21 +140,19 @@ int32 GPS_Serial_Packet_Read(gpsdevh *fd, GPS_PPacket *packet)
            if(u == ETX)
                if(isDLE)
                {
-                   (*packet)->edle = DLE;
-                   (*packet)->etx = ETX;
                    if(p-(*packet)->data-2 != (*packet)->n)
                    {
                        GPS_Error("GPS_Packet_Read: Bad count");
                        gps_errno = FRAMING_ERROR;
                        return 0;
                    }
-                   (*packet)->chk = *(p-2);
+                   chk_read = *(p-2);
 
                    for(i=0,p=(*packet)->data;i<(*packet)->n;++i)
                        chk -= *p++;
                    chk -= (*packet)->type;
                    chk -= (*packet)->n;
-                   if(chk != (*packet)->chk)
+                   if(chk != chk_read)
                    {
                        GPS_Error("CHECKSUM: Read error\n");
                        gps_errno = FRAMING_ERROR;
index d863683d9fc0b00ac1109b45d88cf4c980f27270..80801a0c731023550265ef170bbe38eabe8a5fbf 100644 (file)
 #include <ctype.h>
 
 
-/* @func GPS_Make_Packet ***********************************************
+/* @funcstatic Build_Serial_Packet *************************************
 **
-** Forms a complete packet to send 
-**
-** @param [w] packet [GPS_PPacket *] packet string
-** @param [r] type [UC] packet type
-** @param [r] data [UC *] data string
-** @param [r] n [int16] number of bytes in data string
+** Forms a complete packet to send on serial port
+*
+** @param [r] in [GPS_PPacket *] packet string with portable packet data
+** @param [w] out [GPS_Serial_PPacket *] packet string suitable for serial port
 **
-** @return [void]
+** @return [US] number of data bytes to send
 ************************************************************************/
-
-void GPS_Serial_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n)
+static US
+Build_Serial_Packet(GPS_PPacket in, GPS_Serial_PPacket out)
 {
     UC *p;
     UC *q;
     
     int32 i;
     UC  chk=0;
+    US  bytes=0;
 
-    
-    p = data;
-    q = (*packet)->data;
+    p = in->data;
+    q = out->data;
 
-    (*packet)->dle   = DLE;
-    (*packet)->edle  = DLE;
-    (*packet)->etx   = ETX;
-    (*packet)->n     = (UC) n;
-    (*packet)->type  = type;
-    (*packet)->bytes = 0;
+    out->dle   = DLE;
+    out->edle  = DLE;
+    out->etx   = ETX;
+    out->n     = in->n;
+    out->type  = in->type;
 
-    chk -= type;
+    chk -= in->type;
 
-    if(n == DLE)
+    if(in->n == DLE)
     {
-       ++(*packet)->bytes;
+       ++bytes;
        *q++ = DLE;
     }
     
+    chk -= in->n;
     
-    chk -= (UC) n;
-    
-    for(i=0;i<n;++i)
+    for(i = 0; i < in->n; ++i)
     {
        if(*p == DLE)
        {
-           ++(*packet)->bytes;
+           ++bytes;
            *q++ = DLE;
        }
        chk -= *p;
        *q++ = *p++;
-       ++(*packet)->bytes;
+       ++bytes;
     }
 
     if(chk == DLE)
     {
        *q++ = DLE;
-       ++(*packet)->bytes;
+       ++bytes;
     }
     
-    (*packet)->chk = chk;
+    out->chk = chk;
     
-    return;
+    return bytes;
 }
 
 
@@ -130,11 +126,21 @@ int32 GPS_Serial_Write_Packet(gpsdevh *fd, GPS_PPacket packet)
 {
     size_t ret;
     const char *m1, *m2;
-    
+    GPS_Serial_OPacket ser_pkt;
+    UC ser_pkt_data[MAX_GPS_PACKET_SIZE * sizeof(UC)];
+    US bytes;
 
+    if (packet->type >= 0xff || packet->n >= 0xff) {
+       GPS_Error("SEND: Unsupported packet type/size for serial protocol");
+        return 0;
+    }
+    
+    ser_pkt.data = ser_pkt_data;
+    bytes = Build_Serial_Packet(packet, &ser_pkt);
+    
     GPS_Diag("Tx Data:");
-    Diag(&packet->dle, 3);    
-    if((ret=GPS_Serial_Write(fd,(const void *) &packet->dle,(size_t)3)) == -1)
+    Diag(&ser_pkt.dle, 3);    
+    if((ret=GPS_Serial_Write(fd,(const void *) &ser_pkt.dle,(size_t)3)) == -1)
     {
        perror("write");
        GPS_Error("SEND: Write to GPS failed");
@@ -146,29 +152,29 @@ int32 GPS_Serial_Write_Packet(gpsdevh *fd, GPS_PPacket packet)
        return 0;
     }
 
-    Diag(packet->data, packet->bytes);
-    if((ret=GPS_Serial_Write(fd,(const void *)packet->data,(size_t)packet->bytes)) == -1)
+    Diag(ser_pkt.data, bytes);
+    if((ret=GPS_Serial_Write(fd,(const void *)ser_pkt.data,(size_t)bytes)) == -1)
     {
        perror("write");
        GPS_Error("SEND: Write to GPS failed");
        return 0;
     }
-    if(ret!=packet->bytes)
+    if(ret!=bytes)
     {
        GPS_Error("SEND: Incomplete write to GPS");
        return 0;
     }
 
 
-    Diag(&packet->chk, 3);
+    Diag(&ser_pkt.chk, 3);
 
     GPS_Diag(": ");
-    DiagS(packet->data, packet->bytes);
-    DiagS(&packet->chk, 3);
-    m1 = Get_Pkt_Type(packet->type, packet->data[0], &m2);
+    DiagS(ser_pkt.data, bytes);
+    DiagS(&ser_pkt.chk, 3);
+    m1 = Get_Pkt_Type(ser_pkt.type, ser_pkt.data[0], &m2);
     GPS_Diag("(%-8s%s)\n", m1, m2 ? m2 : "");
 
-    if((ret=GPS_Serial_Write(fd,(const void *)&packet->chk,(size_t)3)) == -1)
+    if((ret=GPS_Serial_Write(fd,(const void *)&ser_pkt.chk,(size_t)3)) == -1)
     {
        perror("write");
        GPS_Error("SEND: Write to GPS failed");
index edd3f5b0daa58482f653e5d78821fe01ae87bc58..2b6fc91155d814cc36dcc1e96f7671583f9f6b86 100644 (file)
@@ -11,11 +11,10 @@ extern "C"
 
 #define GPS_ARB_LEN 1024
 
-void   GPS_Serial_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n);    
 int32  GPS_Serial_Write_Packet(gpsdevh *fd, GPS_PPacket packet);
 int32  GPS_Serial_Send_Ack(gpsdevh *fd, GPS_PPacket *tra, GPS_PPacket *rec);
 
-void   GPS_Make_Packet(GPS_PPacket *packet, UC type, UC *data, int16 n);    
+void   GPS_Make_Packet(GPS_PPacket *packet, US type, UC *data, uint32 n);    
 
 
 #endif
index 35ac8d684bb26fa61d4fb9377e438da49d2d922b..26d1264c38cdc39a56d9e20c762f865d1504b99d 100644 (file)
@@ -84,6 +84,7 @@ gusb_cmd_get(garmin_usb_packet *ibuf, size_t sz)
        int rv;
        unsigned char *buf = (unsigned char *) &ibuf->dbuf;
        int orig_receive_state;
+       unsigned short pkt_id;
 top:
        orig_receive_state = receive_state;
        switch (receive_state) {
@@ -97,6 +98,7 @@ top:
                fatal("Unknown receiver state %d\n", receive_state);
        }
 
+       pkt_id = le_read16(&ibuf->gusb_pkt.pkt_id);
        if (gps_show_bytes) {
                int i;
                const char *m1, *m2;
@@ -121,13 +123,13 @@ top:
                        GPS_Diag("%c", isalnum(buf[i])? buf[i] : '.');
                }
 
-               m1 = Get_Pkt_Type(ibuf->gusb_pkt.pkt_id[0], pkttype, &m2);
+               m1 = Get_Pkt_Type(pkt_id, pkttype, &m2);
 if ((rv == 0)  &&  (receive_state == rs_frombulk) ) {m1= "RET2INTR";m2=NULL;};
                GPS_Diag("(%-8s%s)\n", m1, m2 ? m2 : "");
        }
 
        /* Adjust internal state and retry the read */
-       if ((rv > 0) && (ibuf->gusb_pkt.pkt_id[0] == GUSB_REQUEST_BULK)) {
+       if ((rv > 0) && (pkt_id == GUSB_REQUEST_BULK)) {
                receive_state = rs_frombulk;
                goto top;
        }
@@ -158,6 +160,7 @@ gusb_cmd_send(const garmin_usb_packet *opkt, size_t sz)
 
        if (gps_show_bytes) {
                const unsigned short pkttype = le_read16(&opkt->gusb_pkt.databuf[0]);
+               const unsigned short pkt_id = le_read16(&opkt->gusb_pkt.pkt_id);
                GPS_Diag("TX [%d]:", sz);
 
                for(i=0;i<sz;i++)
@@ -166,7 +169,7 @@ gusb_cmd_send(const garmin_usb_packet *opkt, size_t sz)
                for(i=0;i<sz;i++)
                        GPS_Diag("%c", isalnum(obuf[i])? obuf[i] : '.');
 
-               m1 = Get_Pkt_Type(opkt->gusb_pkt.pkt_id[0], pkttype, &m2);
+               m1 = Get_Pkt_Type(pkt_id, pkttype, &m2);
 
                GPS_Diag("(%-8s%s)\n", m1, m2 ? m2 : "");
         }
index e266011ddaed5c946e815c94b9f20d5396b161bb..d061f312abbd4e62130f735f55c8ce540c82b64a 100644 (file)
@@ -71,7 +71,7 @@ do_over:
         */
        (*packet)->type = le_read16(&pkt.gusb_pkt.pkt_id);
        payload_size = le_read32(&pkt.gusb_pkt.datasz);
-       (*packet)->n = (UC) payload_size;
+       (*packet)->n = payload_size;
        memcpy((*packet)->data, &pkt.gusb_pkt.databuf, payload_size);
        
        return 1;
index bd376b7e0f2fd09497e2f142f2c548e8c76ff56e..9aee54c7e3b7cd9f89ab4fbb61d9458c89064afa 100644 (file)
 #include "garminusb.h"
 #include "gpsusbint.h"
 
-void 
-GPS_Make_Packet_usb(GPS_PPacket *packet, UC type, UC *data, int16 n)
-{
-       /*
-        * For the USB case, it's a little tacky that we just copy
-        * the params into *packet, but we really don't have any manipulations
-        * to do here.   They're done in send_packet in order to keep the
-        * contents of *packet identical for the serial and USB cases.
-        */
-
-       (*packet)->type = type;
-       memcpy((*packet)->data, data, n);
-       (*packet)->n = (UC) n;
-       
-       return;
-}
-
 int32
 GPS_Write_Packet_usb(gpsdevh *dh, GPS_PPacket packet)
 {